use rand::{thread_rng, Rng};
use std::{cmp::Ordering, io};
fn main() {
    println!("猜数字游戏开始！");

    let result_num = thread_rng().gen_range(0..100);

    println!("数字是{}", result_num);

    loop {
        println!("输入猜测的数字");
        
        let mut guess_num = String::new();

        io::stdin().read_line(&mut guess_num).expect("错误");

        let guess_num: u32 = match guess_num.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        };

        match guess_num.cmp(&result_num) {
            Ordering::Less => println!("小了"),
            Ordering::Equal => {
                println!("对了");
                break;
            }
            Ordering::Greater => println!("大了"),
        }
    }
}
